package com.wiringweb.parameterprocessor.implementation;

import com.gooddies.utils.IterableEnumeration;
import com.wiringweb.data.QueryParameters;
import com.wiringweb.parameterprocessor.ParameterProcessorInterface;
import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Dmitry
 */
public class QueryParametersImpl extends ParameterProcessorInterface {

    @Override
    public Object process(HttpServletResponse response, HttpServletRequest request, String[] urlParameter, int parameterIndex) {
        Map<String, String> hashMap = new HashMap<String, String>(10);
        for (String key : IterableEnumeration.make(request.getParameterNames())) {
            String value = request.getParameter(key);
            hashMap.put(key, value);
        }
        QueryParameters params = new QueryParameters(hashMap);
        return params;
    }

    @Override
    public ParameterProcessorInterface construct(Class argumentType, Annotation annotation) {
        return new QueryParametersImpl();

    }

}
